//
//  logger.hpp
//  DemoV2
//
//  Created by 董一龙 on 2022/8/5.
//

#ifndef logger_hpp
#define logger_hpp

#include <stdio.h>
#include <string>
#include "MPSCRingBuffer.hpp"

/// 写数据到文件，支持多线程写数据
class Logger final {
public:
    static void setLogFileName(std::string const& filename);
    void syncLog(std::string const& msg);
    void syncLog(void const* src, uint32_t bytes);
    void asyncLog(std::string const& msg);
    void asyncLog(void const* src, uint32_t bytes);
    static Logger& getInstance();
    
    Logger(Logger const&) = delete;
    Logger(Logger &&) = delete;
    Logger& operator=(Logger const&) = delete;
    Logger& operator=(Logger &&) = delete;
private:
    Logger();
    ~Logger();
    static void writeLog();
    static constexpr uint32_t buffer_size = 1024 * 256;
    static FILE* logFilePtr;
    static MPSCRingBuffer<buffer_size> ringBuffer;
    static std::string logFileName;
};

#endif /* logger_hpp */
